package com.mybatis.controller.shop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mybatis.basic.entity.AjaxJson;
import com.mybatis.entity.shop.GoodsType;
import com.mybatis.service.shop.GoodsTypeService;

@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {

	@Autowired
	private GoodsTypeService goodsTypeService;

	//功能主页面
	@RequestMapping("/page")
	public String menuPage(Model model){
		return "goods/goodstype/list";
	}

	//分页数据
	@RequestMapping("/pageList")
	@ResponseBody
	public AjaxJson pageList(GoodsType goodsType){
		return goodsTypeService.queryListByPage(goodsType);
	}

	//新增
	@RequestMapping(value = "/manage",method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson add(GoodsType goodsType,Integer level){
		return goodsTypeService.add(goodsType,level);
	}

	//修改页面
	@RequestMapping(value = "/editPage/{id}", method = RequestMethod.GET)
	public String updatePage(@PathVariable(value = "id") int id,Model model){
		if(id!=0){
			System.err.println(id);
			model.addAttribute("m",goodsTypeService.queryOne(id).getObj());
		}
		return "goods/goodstype/edit";
	}

	//修改
	@RequestMapping(value = "/manage",method = RequestMethod.PUT)
	@ResponseBody
	public AjaxJson update(GoodsType goodsType,Integer level){
		return goodsTypeService.mod(goodsType,level);
	}

	//删除
	@RequestMapping(value = "/manage/{id}",method = RequestMethod.DELETE)
	@ResponseBody
	public AjaxJson del(@PathVariable(value = "id")int id){
		return goodsTypeService.del(id);
	}
}
